'''
Created on 14. jan. 2010

@author: perfp
'''

class Checkout():
    '''
    classdocs
    '''


    def __init__(self, rules):
        '''
        Constructor
        '''
        self.Total = 0
        self.Rules = rules
        self.ItemCount = {"A":0, "B":0, "C":0, "D":0}
        
        
    def Scan(self, items):
        
        for item in items:
            self.ItemCount[item] = self.ItemCount[item] + 1
            
            for itemtype, price, special in self.Rules:
                if item == itemtype:
                    self.Total += price 
                    self.CheckSpecial(itemtype, price, special)
                    
    def CheckSpecial(self, itemtype, price, special):
        if special is not None:
            specialcount, specialprice = special
            
            if self.ItemCount[itemtype] % specialcount == 0:
                self.Total -= price * specialcount
                self.Total += specialprice        